package com.kcwoo.shaokun.rxjavalearning.db

import android.arch.persistence.room.Room
import android.os.Bundle
import android.support.v7.app.AppCompatActivity
import android.util.Log
import com.kcwoo.shaokun.rxjavalearning.R
import kotlinx.android.synthetic.main.activity_main3.*
import kotlin.concurrent.thread


class Main3Activity : AppCompatActivity() {


    lateinit var db: AppDatabase

    lateinit var animalDao: Dao

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main3)


        button6.setOnClickListener {
            thread {
                db = Room.databaseBuilder(applicationContext, AppDatabase::class.java, "animal.db")
                        .build()
                animalDao = db.dao
            }

        }

        button2.setOnClickListener {
            thread {
                repeat(10) {
                    val a = Stu()
                    a.name = "akun"
                    a.age = it * 4
                    animalDao.insert(a)
                }
            }


        }
        button5.setOnClickListener {
            thread {
                animalDao.all.forEach {
                    Log.d("akun", it.toString())
                }
            }


        }


    }
}
